//
//  UploadTask.h
//  Scanner
//
//  Created by apple on 15-5-17.
//  Copyright (c) 2015年 米明. All rights reserved.
//

#import "LYObject.h"
#import "Goods.h"
#import <AssetsLibrary/AssetsLibrary.h>
//AFNetWorking网络管理
#import "AFNetworkActivityIndicatorManager.h"
//AFNetWorking网络下载
#import "AFNetworking.h"

#define UPLOAD_PHOTO_URL @"http://182.254.221.46:8081/index/upload"

@class UploadTask;

/**
 *  上传任务代理
 */
@protocol UploadTaskDelegate <NSObject>

@optional
/**
 *  上传进度
 *
 *  @param uploadTask 上传任务实例
 *  进度
 */
-(void)uploadTask:(UploadTask *)uploadTask totalBytesWritten:(long long)totalBytesWritten totalBytesExpectedToWrite:(long long)totalBytesExpectedToWrite;

/**
 *  上传成功
 *
 *  @param uploadTask 上传任务实例
 *  @param succeed    是否上传成功
 */
-(void)uploadTask:(UploadTask *)uploadTask succeed:(BOOL)succeed;

/**
 *  上传失败
 *
 *  @param uploadTask 上传任务实例
 *  @param error      错误信息
 */
-(void)uploadTask:(UploadTask *)uploadTask error:(NSError *)error;

@end

@interface UploadTask : LYObject

@property(nonatomic,assign) id <UploadTaskDelegate> delegate;

//图片
@property(nonatomic,strong)UIImage * photo;

//图片路径
@property(nonatomic,copy)NSString * photoPath;

//商品实例
@property(nonatomic, strong)Goods * goods;

@property(nonatomic ,assign)BOOL isDid;//是否执行过任务
@property(nonatomic, assign)BOOL succeed;//已成功
@property(nonatomic, assign)BOOL isUploading;//正在上传

//创建时间
//goodsID+01
@property(nonatomic,assign)NSInteger number;//序号

@property(nonatomic,strong)AFHTTPRequestOperation *operation;

@property(nonatomic,strong)NSURLSessionUploadTask * uploadTask;

/**
 *  通过图片创建上传任务实例
 *
 *  @param photo 图片实例
 *  @param goods 商品实例
 *
 *  @return id
 */
-(instancetype)initWithPhoto:(UIImage *)photo goods:(Goods*)goods;

/**
 *  通过图片路径创建上传任务实例
 *
 *  @param photoPath 图片路径
 *  @param goods     商品实例
 *
 *  @return id
 */
-(instancetype)initWithPhotoPath:(NSString *)photoPath goods:(Goods *)goods;

/**
 *  准备任务
 */
-(void)readyTask;

/**
 *  开始
 */
-(void)startTask;

/**
 *  暂停
 */
-(void)pause;

/**
 *  重新开始
 */
-(void)resume;

/**
 *  停止 置为nil
 */
-(void)stop;


@end


